﻿using mvc315.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace mvc315.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.greeting = "Hello world on friday!";
            ViewBag.pbj = "Peanut butter & jelly";
            
            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            TodoIndexVM tempVm = new TodoIndexVM();
            
            tempVm.Greeting = "Yo from contacts....";

            var tempResults = DataHolder.GetTodos();
            var filteredRes = tempResults.Where(t => t.Category == "k").ToList();
            tempVm.MyChores = filteredRes;

            return View(tempVm);
        }
        // for the create page
        public ActionResult Create()
        {
            return View();
        }

        // Show the list of Todo...
        public ActionResult TodosPage()
        {
            ViewBag.TodoGreeting = "Here are the chores....";

            TodoIndexVM viewModel = new TodoIndexVM();
            
            viewModel.Greeting = "The Chores are: ";

            // getthelist ... DataHolder.GetTodos();
            // LINQ to filter against getthelist, return all that Ctegoryy == "c"
            
            // get 1st

            viewModel.MyChores = DataHolder.GetTodos();
            return View(viewModel);
        }


    }
    // Data holder...
    public static class DataHolder
    {
        public static List<Todo> GetTodos(){

            List<Todo> tList = new List<Todo>(){
              new Todo(){Id=100, Task="clean garage", IsCompleted=false, DateCreated=DateTime.Now.AddDays(-7), Category="c"},
              new Todo(){Id=101, Task="wash dishes", IsCompleted=true, DateCreated=DateTime.Now.AddDays(-6), Category="c"},
              new Todo(){Id=300, Task="vaccum", IsCompleted=false, DateCreated=DateTime.Now.AddDays(-5), Category="k"}
            };
            return tList;
        }
    }


}